package cn.zn.modules.pz.his.service.impl;

import cn.zn.modules.pz.his.entity.PzRequest;
import cn.zn.modules.pz.his.entity.QPzRequest;
import cn.zn.modules.pz.his.repository.PzRequestRepository;
import cn.zn.modules.pz.his.service.PzRequestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
@Slf4j
public class PzRequestServiceImpl implements PzRequestService {

    @Autowired
    private PzRequestRepository pzRequestRepository;

    @Override
    public List<PzRequest> findByMainIds(Integer ap, List<String> mainIds) {
        QPzRequest qpzRequest = QPzRequest.pzRequest;
        return (List<PzRequest>) pzRequestRepository.findAll(qpzRequest.ap.eq(ap).and(qpzRequest.mainId.in(mainIds)));
    }

    @Override
    public PzRequest findByMainId(Integer ap, String mainId) {
        QPzRequest qpzRequest = QPzRequest.pzRequest;
        Optional<PzRequest> one = pzRequestRepository.findOne(qpzRequest.ap.eq(ap).and(qpzRequest.mainId.eq(mainId)));
        if (one.isPresent()) {
            return one.get();
        }
        return null;
    }
}
